package com.ruoyi.graduate.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.graduate.domain.entity.MsDelog;
import com.ruoyi.graduate.domain.param.MsDelogAddParam;
import com.ruoyi.graduate.domain.param.MsDelogPageListParam;
import com.ruoyi.graduate.service.IMsDelogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * 弹窗控制接口
 */
@RestController
@RequestMapping("/api/delog")
@Api(tags = "弹窗控制接口")
public class MsDelogController extends BaseController {

    @Autowired
    private IMsDelogService msDelogService;


    @ApiOperation("用户获取弹窗列表")
    @GetMapping("/{customerId}")
    public AjaxResult getMsDelog(@PathVariable("customerId") Long customerId) {

        return msDelogService.listVo(customerId);
    }


    @ApiOperation("管理端弹窗新增")
    @PostMapping
    public AjaxResult addMsDelog(@RequestBody MsDelogAddParam param) {

        return msDelogService.add(param);
    }


    @ApiOperation("管理端分页查询弹窗列表")
    @GetMapping("/page")
    public TableDataInfo pageList(MsDelogPageListParam param){

        PageInfo pageInfo = msDelogService.pageList(param);

        return getDataTable(pageInfo.getList(),pageInfo.getTotal());
    }


    @ApiOperation("弹窗删除")
    @DeleteMapping("/{delogId}")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult deleteMsDelog(@PathVariable("delogId") Integer delogId) {

        boolean b = msDelogService.removeById(delogId);

        return b ? AjaxResult.success() : AjaxResult.error();
    }

}
